package com.thauanLopes.bacterium;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.TextView;

import com.game.ThauanFramework.BitmapStorage;
import com.game.ThauanFramework.Util;
import com.thauanLopes.bacterium.GameManages.ScoreManager;
import com.thauanLopes.smagasmaga.R;

public class Menu extends Activity {

	private final String TAG = "Activity - Menu";

	ImageButton button_play;
	ImageButton button_credits;
	TextView textView_highScore;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Util.setCurrentActivity(this);

		// Por para carregar em Splash Screen
		BitmapStorage.getInstance();
		ScoreManager.Setup();

//		 Screen adjustments
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		// Request landscape orientation
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

		Log.i(TAG,
				String.valueOf(getResources().getConfiguration().orientation));

		// if orientation is horizontal
		if (getResources().getConfiguration().orientation == 2) {
			Util.setAbriuActivity(true);

		}

		Create();

	}

	@Override
	protected void onStart() {
		super.onStart();
		Start();
	}

	private void Create() {

		if (Util.isAbriuActivity()) {

			setContentView(R.layout.activity_menu);

			this.button_play = (ImageButton) findViewById(R.id.imageButton_play);
			this.button_play.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					button_play
							.setBackgroundResource(R.drawable.monstros_play_pressed);
					Util.ChangeActivity(Ac_GamePlay.class);
				}
			});

			// this.button_credits = (ImageButton)
			// findViewById(R.id.imageButton_credits);
			// this.button_credits.setOnClickListener(new OnClickListener() {
			//
			// @Override
			// public void onClick(View v) {
			// // TODO Auto-generated method stub
			// Util.ChangeActivity(AcCreditos.class);
			// }
			// });

			this.textView_highScore = (TextView) findViewById(R.id.textView_menu_highscore);
			this.textView_highScore.setTypeface(Util.getGameTypeface());

		}
	}

	private void Start() {

		if (Util.isAbriuActivity()) {

			this.button_play.setBackgroundResource(R.drawable.monstros_play);

			int highScore = ScoreManager.getHighScore();
			this.textView_highScore.setText(String.valueOf(highScore));
		}
	}

}
